package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.AdminDao;
import com.baizhi.springboot.entity.Admin;
import com.baizhi.springboot.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;
    @Override
    public Admin login(Admin admin) {
        Admin admin1 = adminDao.selectByName(admin.getUsername());
        if (admin1 != null) {
            if (admin1.getPassword().equals(admin.getPassword())) {
                return admin1;
            } else {
                throw new RuntimeException("密码错误！");
            }
        } else {
            throw new RuntimeException("账号错误！");
        }

    }

    @Override
    public Admin selectByName(String username) {
        return adminDao.selectByName(username);
    }
}
